function List(contextPath,divContainer){
	View.apply(this,arguments);
	this.initExtendedDiv();
	this.lastRequestObject = null;
	this.menuClickHandler = null;
	this.downloadFrame = null;
	this.selectedRowIndexArray = [];
	
	this.beforeRefresh = function(){
		if(this.dataModel){
			return '<div class="checklist"><table cellpadding="2" cellspacing="0">'+buildListTitle(this.getTitleArray())+buildListData(this.getDataArray(),this.getTitleArray())+'</table></div>'+buildListFooter(this.getFooterArray());
		}else{
			return "";
		}
	};
	this.afterRefresh = function(){
		this.divContainer.children[0].style.height = (this.divContainer.offsetHeight-22)+"px";
	};
	
	this.exportExcel = function(fileName){
		if(this.lastRequestObject!==null){
			this.lastRequestObject.requestAction.inspectorName = "ExportInspector";
			this.lastRequestObject.fileName = fileName;
			var requestString = window["Comm"].convertToJSON(this.lastRequestObject);
			if(this.downloadFrame===null){
				this.downloadFrame = document.createElement("iframe");
				this.downloadFrame.style.display = "none";
				document.body.appendChild(this.downloadFrame);
			}
			this.downloadFrame.src = this.contextPath+"/download.jsp?requestString="+encodeURIComponent(requestString);
		}
	};
	
	this.getListRow = function(rowIndex){
		var tableArray = this.divContainer.getElementsByTagName("TABLE");
		if(tableArray.length>0){
			return tableArray[0].rows(parseInt(rowIndex,10));
		}
		return null;
	};
	
	this.deleteSelectedListRow = function(){
		var selectedLength = this.selectedRowIndexArray.length;
		var contextPath = this.contextPath;
		var uidArray = [];
		var dealSelectResult = function(evt){
			var buttonIndex = evt.srcElement.buttonindex;
			var action = "delete";
			if(buttonIndex=="0"){
				var condition = tableName+".OID IN "+"("+uidArray.join(",")+")";
				var tempObject = new Object();
				tempObject.returnTip = "common.tip."+action+"succeed";
				var requestObject = window["Comm"].buildRequestObject(action,null,null,tableName,null,condition,null,null,null,null,tempObject);	
				var resultObject = window["Comm"].sendRequest(contextPath,requestObject);
				if(resultObject&&resultObject.returnTip){
					window["Comm"].showPopWindow(contextPath,"common.title.promptinfo",resultObject.returnTip,"common.button.ok",resultObject.exceptionMessage);
				}
			}
		};
		if(selectedLength>0){
			var tableName = this.lastRequestObject.requestAction.tableName;
			var popObject = window["Comm"].showPopWindow(this.contextPath,"common.title.selectinfo","common.tip.ifdelete","common.button.yes,common.button.no");
			popObject.registerEventProcessor("afterClick0",dealSelectResult);
			for(var i=0;i<selectedLength;i++){
				var uid = this.getListRow(this.selectedRowIndexArray[i])["OID"];
				uidArray.push("'"+uid+"'");
			}
		}else{
			window["Comm"].showPopWindow(this.contextPath,"common.title.promptinfo","common.tip.noselectedinfo",null,null);
		}
	};
	
	this.insertListRow = function(templateName){
		var tableName = this.lastRequestObject.requestAction.tableName;
		var condition = tableName+".OID='-1'";
		var requestObject = window["Comm"].buildRequestObject("query",null,templateName,tableName,null,condition,null,null,null,null);
		var resultObject = window["Comm"].sendRequest(this.contextPath,requestObject);
		window["Comm"].showPopWindow(this.contextPath,"common.title.insertinfo",resultObject,"common.button.ok,common.button.cancel",null);
	};
	
	this.updateSelectedListRow = function(templateName){
		var selectedLength = this.selectedRowIndexArray.length;
		if(selectedLength<=1){
			var tableName = this.lastRequestObject.requestAction.tableName;
			var uid = this.getListRow(this.selectedRowIndexArray[0])["OID"];
			var condition = tableName+".OID='"+uid+"'";
			var requestObject = window["Comm"].buildRequestObject("query",null,templateName,tableName,null,condition,null,null,null,null);
			var resultObject = window["Comm"].sendRequest(this.contextPath,requestObject);
			window["Comm"].showPopWindow(this.contextPath,"common.title.updateinfo",resultObject,"common.button.ok,common.button.cancel",null);
		}else if(selectedLength>1){
			window["Comm"].showPopWindow(this.contextPath,"common.title.promptinfo","common.tip.noselectedinfo",null,null);
		}else{
			window["Comm"].showPopWindow(this.contextPath,"common.title.promptinfo","common.tip.noselectedinfo",null,null);
		}
	};
	
	this.cacheComponent = function(cacheId){
		var tempObject = new Object();
		tempObject.lastRequestObject = this.lastRequestObject;
		tempObject.selectedRowIndexString = this.selectedRowIndexArray.join(",");
		tempObject.functionId = this.functionId;
		tempObject.containerHtml = this.divContainer.innerHTML;
		if(!this.cacheObject){
			this.cacheObject = new Object();
		}
		this.cacheObject[cacheId] = tempObject;
		this.selectedRowIndexArray = [];
	};
	
	this.loadComponent = function(cacheId){
		if(this.cacheObject&&this.cacheObject[cacheId]){
			var tempObject = this.cacheObject[cacheId];
			this.lastRequestObject = tempObject.lastRequestObject;
			this.selectedRowIndexArray = tempObject.selectedRowIndexString.length>0?tempObject.selectedRowIndexString.split(","):[];
			this.functionId = tempObject.functionId;
			this.divContainer.innerHTML = tempObject.containerHtml;
		}
	};
	
	function buildListTitle(titleArray){
		var titleHtmlArray = ['<tr class="titlerow"><th>&nbsp;</th>'];
		var titleArrayLength = titleArray.length;
		for(var i=0;i<titleArrayLength;i++){
			var titleObject = titleArray[i];
			if(titleObject["ISHIDDEN"]!="1"){
				titleHtmlArray.push('<th');
				for(var ele in titleObject){
					titleHtmlArray.push(" "+ele+'='+titleObject[ele]);
				}
				titleHtmlArray.push('>&nbsp;'+titleObject["DISPLAYNAMETEXT"]+'&nbsp;</th>');
			}
		}
		titleHtmlArray.push('</tr>');
		return titleHtmlArray.join('');
	}
	
	function buildListData(dataArray,titleArray){
		var dataHtmlArray = [];
		var dataArrayLength = dataArray.length;
		for(var i=0;i<dataArrayLength;i++){
			var dataHtml = '<tr@property><td class="numtd" align="center">'+(i+1)+'</td>';
			var propertyHtml = "";
			for(var j=0;j<titleArray.length;j++){
				var text = dataArray[i][titleArray[j].FIELDNAME+"TEXT"]||dataArray[i][titleArray[j].FIELDNAME]||'&nbsp;';
				if(titleArray[j]["ISHIDDEN"]!="1"){
					dataHtml+='<td>'+text+'</td>';
				}else{
					propertyHtml+=" "+titleArray[j].FIELDNAME+"="+text;
				}
			}
			dataHtml = dataHtml.replace("@property",propertyHtml)+'</tr>';
			dataHtmlArray.push(dataHtml);
		}
		return dataHtmlArray.join('');
	}
	
	function buildListFooter(footerArray){
		var footerHtml = "";
		if(footerArray&&footerArray.length>0){
			var footerObject = footerArray[0];
			var footerString = footerObject["footerString"];
			var allSize = footerObject["ALLSIZE"];
			var pageSize = footerObject["pageSize"];
			var firstRecord = footerObject["firstRecord"];
			footerString = footerString.replace("ALLSIZE",allSize);
			footerString = footerString.replace("PAGESIZE",pageSize);
			var listNum = ["&nbsp;&nbsp;&nbsp;"];
			var pageNum = Math.ceil(allSize/pageSize);
			for(var i=1;i<=pageNum;i++){
				if(i==(firstRecord/pageSize+1)){
					listNum.push('<span pageSize="'+pageSize+'" style="color:red" clicked="true">'+i+'&nbsp;&nbsp;&nbsp;</span>');
					if(i==1){
						footerString = footerString.replace('step="-1"','step="-1" disabled');
					}
					if(i==pageNum){
						footerString = footerString.replace('step="1"','step="1" disabled');
					}
				}else{
					listNum.push('<span pageSize="'+pageSize+'">'+i+'&nbsp;&nbsp;&nbsp;</span>');
				}
			}
			footerString = footerString.replace("LISTNUM",listNum.join(""));
			footerHtml = '<div class="footer">&nbsp;'+footerString+'</div>';
		}
		return footerHtml;
	}
}

List.prototype = new View();
List.prototype.getSelectedRowIndexArray = function(){
	return this.selectedRowIndexArray||[];
};

List.prototype.handleMouseOverEvent0 = function(evt){
	var handleObject = evt.srcElement;
	if(handleObject.tagName=="TD"&&handleObject.parentElement.className!="selectedrow"){
		handleObject.parentElement.className = "mouseoverrow";
	}else if(handleObject.tagName=="SPAN"){
		handleObject.style.color = "red";
		handleObject.style.cursor = "hand";
	}
};

List.prototype.handleMouseOutEvent0 = function(evt){
	var handleObject = evt.srcElement;
	if(handleObject.tagName=="TD"&&handleObject.parentElement.className!="selectedrow"){
		handleObject.parentElement.className = "mouseoutrow";
	}else if(handleObject.tagName=="SPAN"&&handleObject.clicked!="true"){
		handleObject.style.color = "black";
		handleObject.style.cursor = "";
	}
};

List.prototype.handleClickEvent0 = function(evt){
	var handleObject = evt.srcElement;
	if(handleObject.tagName=="TD"){
		function clearSelectedRow(selectedRowIndexArray,tableObject){
			for(var n=0;n<selectedRowIndexArray.length;n++){
				tableObject.rows(parseInt(selectedRowIndexArray[n],10)).className = "";
			}
			selectedRowIndexArray.length = 0;
		}
		function addSingleSelectedRow(rowIndex,selectedRowIndexArray,tableObject){
			tableObject.rows(rowIndex).className = "selectedrow";
			selectedRowIndexArray.push(rowIndex);
		}
		var rowObject = handleObject.parentElement;
		var tableObject = handleObject.parentElement.parentElement;
		if(evt.shiftKey){
			if(this.selectedRowIndexArray.length===0){
				addSingleSelectedRow(rowObject.rowIndex,this.selectedRowIndexArray,tableObject);
			}else{
				var preRowIndex = parseInt(this.selectedRowIndexArray.pop(),10);
				var curRowIndex = rowObject.rowIndex;
				var step = preRowIndex>curRowIndex?-1:1;
				clearSelectedRow(this.selectedRowIndexArray,tableObject);
				for(var m=preRowIndex;m*step<=curRowIndex*step;m=m+step){
					addSingleSelectedRow(m,this.selectedRowIndexArray,tableObject);
				}
			}
		}else if(evt.altKey||evt.ctrlKey){
			if(rowObject.className=="selectedrow"){
				rowObject.className = "";
				for(var j=0;j<this.selectedRowIndexArray.length;j++){
					if(this.selectedRowIndexArray[j]==rowObject.rowIndex){
						this.selectedRowIndexArray.splice(j,1);
						break;
					}
				}
			}else{
				addSingleSelectedRow(rowObject.rowIndex,this.selectedRowIndexArray,tableObject);
			}
		}else{
			clearSelectedRow(this.selectedRowIndexArray,tableObject);
			addSingleSelectedRow(rowObject.rowIndex,this.selectedRowIndexArray,tableObject);
		}
	}else if(handleObject.tagName=="TH"){
		var lastOrderString = this.lastRequestObject.requestAction.orderBy;
		var nextOrderString = handleObject["TABLENAME"]+"."+handleObject["FIELDNAME"];
		if(lastOrderString&&lastOrderString.indexOf(nextOrderString)>-1){
			if(lastOrderString.indexOf("ASC")>-1){
				this.lastRequestObject.requestAction.orderBy = nextOrderString +" DESC";
			}else{
				this.lastRequestObject.requestAction.orderBy = "";
			}
		}else{
			this.lastRequestObject.requestAction.orderBy = nextOrderString +" ASC";
		}
		this.dataModel = window["Comm"].sendRequest(this.contextPath,this.lastRequestObject);
		this.refresh();
		var thArray = this.divContainer.getElementsByTagName("TH");
		for(var i=0;i<thArray.length;i++){
			if(this.lastRequestObject.requestAction.orderBy.indexOf(thArray[i]["TABLENAME"]+"."+thArray[i]["FIELDNAME"])>-1){
				if(this.lastRequestObject.requestAction.orderBy.indexOf("ASC")>-1){
					thArray[i].innerText = window["Comm"].trim(thArray[i].innerText)+"↑";
				}else{
					thArray[i].innerText = window["Comm"].trim(thArray[i].innerText)+"↓";
				}
			}else{
				if(thArray[i].innerText.indexOf("↑")>-1||thArray[i].innerText.indexOf("↓")>-1){
					thArray[i].innerText = "&nbsp;"+thArray[i].innerText.replace("↑","").replace("↓","")+"&nbsp;";
				}
			}
		}
	}else if(handleObject.tagName=="SPAN"){
		this.selectedRowIndexArray = [];
		var pageNum = handleObject.innerText;
		var firstRecord = (parseInt(pageNum,10)-1)*parseInt(handleObject.pageSize,10);
		this.lastRequestObject.requestAction.firstRecord = firstRecord;
		this.dataModel = window["Comm"].sendRequest(this.contextPath,this.lastRequestObject);
		this.refresh();
	}else if(handleObject.tagName=="A"){
		if(handleObject.disabled){
			return;
		}
		this.selectedRowIndexArray = [];
		var pageNumArray = handleObject.parentElement.getElementsByTagName("SPAN");
		for(var i=0;i<pageNumArray.length;i++){
			if(pageNumArray[i].clicked=="true"){
				var pageNum = pageNumArray[i].innerText;
				var firstRecord = (parseInt(pageNum,10)-1+parseInt(handleObject.step))*parseInt(pageNumArray[i].pageSize,10);
				this.lastRequestObject.requestAction.firstRecord = firstRecord;
				this.dataModel = window["Comm"].sendRequest(this.contextPath,this.lastRequestObject);
				this.refresh();
				break;
			}
		}
	}
};

List.prototype.handleMouseUpEvent2 = function(evt){
	var handleObject = evt.srcElement;
	if(handleObject.tagName=="TD"||handleObject.tagName=="TH"){
		var rowObject = handleObject.parentElement;
		if(rowObject.className!="selectedrow"&&handleObject.tagName=="TD"){
			var length = this.selectedRowIndexArray.length;
			for(var n=0;n<length;n++){
				handleObject.parentElement.parentElement.rows(parseInt(this.selectedRowIndexArray[n],10)).className = "";
			}
			this.selectedRowIndexArray.length = 0;
			rowObject.className = "selectedrow";
			this.selectedRowIndexArray.push(rowObject.rowIndex);
		}
		this.showRightMenu(evt);
	}
};